package com.copa.service.impl;

import com.copa.api.MusicApi;
import com.copa.api.MusicApiFactory;
import com.copa.api.MusicProvider;
import com.copa.entity.Music;
import com.copa.service.MusicService;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author copa
 * @createDate 2022-02-17 22:14
 * @function
 */
public class QQMusicServiceImpl implements MusicService {
    @Override
    public Music searchMusicSync(String musicTitle, Boolean needLink) {
        final MusicApi api = MusicApiFactory.create(MusicProvider.QQ);
        List<Music> result = new ArrayList<>();
        try {
            result = api.searchMusicSync(musicTitle, 0, needLink);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Objects.nonNull(result) && !result.isEmpty() ? result.get(0) : null;
    }
}
